package com.xin.data.simbapesa.device.data

import android.content.Context
import android.os.Build
import com.google.gson.Gson
import com.xin.data.simbapesa.base.BaseParams

import com.xin.data.simbapesa.device.util.GeneralUtil
import com.xin.data.simbapesa.device.util.HardwareUtil
import com.xin.data.simbapesa.device.util.NetworkUtil
import com.xin.data.simbapesa.device.util.StorageUtil

class DeviceInfo(val context: Context, val product: String, val token: String, val path: String) {

    fun fetch(): String? {
        return try {
            val data = hashMapOf<String, Any>().apply {
                put("path", path)
                put("token", token)
                put("product", product)
                put("imei", "")
                put("version", "30")
                put("app", product)
                put("manufacturer", Build.MANUFACTURER ?: "")
                put("brand", Build.BRAND ?: "")
                put("deviceName", Build.DEVICE ?: "")
                put("phoneModel", Build.PRODUCT ?: "")
                put("sysVersion", Build.VERSION.RELEASE ?: "")
                put("mac", NetworkUtil.getMacAddress())
                put("laguage", GeneralUtil.getLanguage())
                put("area", GeneralUtil.getArea())
                put("screenHeight", GeneralUtil.getDeviceHeight(context))
                put("screenWidth", GeneralUtil.getDeviceWidth(context))
                put("networkData", GeneralUtil.getSimOperatorName(context))
                put("frontCameraPixels", HardwareUtil.getFrontCameraPixels(context))
                put("rearCameraPixels", HardwareUtil.getBackCameraPixels(context))
                put("ram", StorageUtil.getRamTotal(context))
                put("rom", StorageUtil.getCashTotal())
                put("ip", NetworkUtil.getIPAddress(context))
                put("ip2", NetworkUtil.getIPAddress(context))
                put("networkEnvironment", GeneralUtil.getNetworkType(context))
                put("cpu", GeneralUtil.getCpuModel())
                put("version", BaseParams.getVersion(context))
            }
            Gson().toJson(data).trim()

        } catch (e: Exception) {
            null
        }
    }
}